import request from '@/utils/request.ts'
import {ICommonResponse, ISqlUpdate} from "@/global.ts";
import React from "react";
import {IData} from "react-jsmind";

export interface IRecently {
    key: string
    recentlyUID: string;
    userUID: number;
    path: string;
    name: string
    describe: string
    time: string
}
export interface DataType {
    key: React.Key;
    recentlyUID: string;
    userUID: number;
    path: string;
    name: string
    describe: string
    time: string
}
export const recentlyList = (data: { name: string }): Promise<ICommonResponse<Array<IRecently>>> => {
    return request({
        url: '/recently/list',
        method: 'POST',
        data
    })
}

export const recently = (data: FormData): Promise<ICommonResponse<{ fileURL: string }>> => {
    return request({
        url: '/upload/recently',
        method: 'POST',
        data
    })
}

export const recentlyAdd = (data: { name: string, describe: string, fileURL: string }): Promise<ICommonResponse<ISqlUpdate>> => {
    return request({
        url: '/recently/add',
        method: 'POST',
        data
    })
}

export const recentlyConfig = (url: string): Promise<IData> => {
    return request({
        url,
        method: 'GET'
    })
}

export const recentlyDel = (list: Array<string>): Promise<ICommonResponse<ISqlUpdate>> => {
    return request({
        url: '/recently/del',
        method: 'POST',
        data: { data: JSON.stringify(list) }
    })
}

export const recentlyDelFile = (fileURL: string): Promise<ICommonResponse<null>> => {
    return request({
        url: '/recently/del/file',
        method: 'POST',
        data: { fileURL }
    })
}

export const recentlyEdit = (data: FormData): Promise<ICommonResponse<null>> => {
    return request({
        url: '/recently/edit',
        method: 'POST',
        data
    })
}

export const recentlyView = (data: { path: string }): Promise<ICommonResponse<IRecently[]>> => {
    return request({
        url: '/recently/view',
        method: 'POST',
        data
    })
}